package com.yidu.InventoryManagement.service.impl;

import com.yidu.InventoryManagement.entity.Fund;
import com.yidu.InventoryManagement.entity.SecurityStock;
import com.yidu.InventoryManagement.entity.Securlty;
import com.yidu.InventoryManagement.mapper.SecurityStockMapper;
import com.yidu.InventoryManagement.service.SecurityStockService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 梁俊
 * @date 2022/12/5
 * &@version 1.0
 */
@Service
public class SecurityStockImpl implements SecurityStockService {
           @Resource
           private SecurityStockMapper securityStockMapper;

    /**
     * 分页模糊查
     * @param page 当前页
     * @param limit 每页显示数
     * @param securityName
     * @param DATE
     * @return
     */
    public List<SecurityStock> selectSecurityStock(int page,int limit,String securityName,String DATE) {
        Map map=new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("securityName",securityName);
        map.put("DATE",DATE);
        return securityStockMapper.selectSecurityStock(map);
    }

    /**
     * 查总行书
     * @param securityName 证券名
     * @param DATE 时间
     * @return
     */
    public int countSecurityStock(String securityName,String DATE) {
        Map map=new HashMap();
        map.put("securityName", securityName);
        map.put("DATE",DATE);
        int count = securityStockMapper.countSecurityStock(map);
        return count;
    }

    /**
     * 批量删除
     * @param securityStockId
     * @return
     */
    public int deleteSecurityStock(String securityStockId) {
        //将id转为数据
        System.out.println(securityStockId);
        String[] split = securityStockId.split(",");
        //创建存放id的集合
        ArrayList<Object> equityDataIdList = new ArrayList<Object>();
        for (String id : split) {
            //将id存入集合
            equityDataIdList.add(id);
        }
        return securityStockMapper.deleteSecurityStock(equityDataIdList);
    }

    /**
     * 查询基金id放到下拉框
     * @return
     */
    @Override
    public List<SecurityStock> funIdSelect() {
        return securityStockMapper.funIdSelect();
    }

    /**
     * 查询债券库存id
     * @return
     */
    @Override
    public List<SecurityStock> securityStockIdSelect() {
        return securityStockMapper.securityStockIdSelect();
    }


    /**
     * 查询证券库存id有没有值
     * @return
     */
    @Override
    public int selectSecurityStockId() {
        return securityStockMapper.selectSecurityStockId();
    }

    /**
     * 证券库存添加
     * @return
     */
    @Override
    public int insertSecurityStock(SecurityStock securityStock) {
        return securityStockMapper.insertSecurityStock(securityStock);
    }

    /**
     * 证券库存修改
     * @param securityStock 对象
     * @return
     */
    @Override
    public int updatesecurityStock(SecurityStock securityStock) {
        return securityStockMapper.updatesecurityStock(securityStock);
    }

    /**
     * 根据证券库存查询基金id,证券id，初期标识
     * @param securityStockId
     * @return
     */
    @Override
    public SecurityStock selectOne(String securityStockId) {
        return securityStockMapper.selectOne(securityStockId);
    }

    /**
     * 下拉表格的查询证券信息
     * @return list 集合
     */
    @Override
    public List<Securlty> selectSecurityyyy(int page, int limit,String securityName) {
        Map map=new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        map.put("securityName",securityName);
        return securityStockMapper.selectSecurityyyy(map);
    }

    /**
     * 下拉表格查询证券信息的行数
     */
    @Override
    public int selectSecurityCount(String securityName) {
        return securityStockMapper.selectSecurityCount(securityName);
    }

    /**
     * 查询基金id
     */
    @Override
    public List<Fund> selectFundId(int page, int limit) {
        Map map=new HashMap();
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return securityStockMapper.selectFundId(map);
    }

    /**
     * 下拉表格查询基金信息的行数
     */
    @Override
    public int selectFund() {
        return securityStockMapper.selectFund();
    }




    /**
     * 生成条件字符串
    // * @param workUser 生成条件的参数
     * @return 条件字符串  and getRightText like '%%'
     */
    public String buildStrWhere(SecurityStock securityStock){
        System.out.println(securityStock.getDate()+"\t"+securityStock.getSecurityName()+"ppppp");
        StringBuffer strWhere=new StringBuffer("");
        if(securityStock.getSecurityName()!=null && !securityStock.getSecurityName().equals(""))
        {
            strWhere.append(" and securityName like '%" +securityStock.getSecurityName() + "%'");
        }
        if(securityStock.getDate()!=null && securityStock.getDate().equals(""))
        {
            strWhere.append(" and ss.DATE like '%" +securityStock.getDate() + "%'");//日期
        }
        return  strWhere.toString();
    }
}

